﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using lumo.display.object2D;

namespace lumo.display.animation2D
{
    /// <summary>
    /// An angle animation for an object.
    /// </summary>
    public class AngleAnimation2D : GenericAnimation2D<IRotationable2D>
    {
        // Private variables
        private float? From = null;
        private float To;
        private Counter RadianCounter = new Counter();

        /// <summary>
        /// Constructor
        /// </summary>
        public AngleAnimation2D(float To, float Time, Smooth Smoothness = Smooth.None, Loop LoopMode = Loop.None, IRotationable2D CurrentObject = null)
            : base(Time, Smoothness, LoopMode, CurrentObject)
        {
            this.To = To;
        }

        /// <summary>
        /// Constructor
        /// </summary>
        public AngleAnimation2D(float? From, float To, float Time, Smooth Smoothness = Smooth.None, Loop LoopMode = Loop.None, IRotationable2D CurrentObject = null)
            : base(Time, Smoothness, LoopMode, CurrentObject)
        {
            this.From = From;
            this.To   = To;
        }

        /// <summary>
        /// Check if finished
        /// </summary>
        public override bool Finished { get { return (RadianCounter.Finished); } }

        /// <summary>
        /// Setup the values
        /// </summary>
        internal override void SetupValues()
        {
            if (!this.From.HasValue)
                this.From = this.CurrentObject.Radians;
            RadianCounter.Reset(this.From.Value, this.To, this.Time, this.Smoothness, this.LoopMode);
        }

        /// <summary>
        /// Update the values.
        /// </summary>
        /// <param name="Game">The game class</param>
        internal override void UpdateValues(LumoComponent Game)
        {
            RadianCounter.Update(Game);
            this.CurrentObject.Radians = RadianCounter.Value;
        }
    }
}
